package com.edgclub.edg.activity;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.RadioButton;
import android.widget.TextView;

import com.edgclub.edg.R;
import com.edgclub.edg.fragment.OtherUserBBFragment;
import com.edgclub.edg.fragment.OtherUserImageFragment;
import com.edgclub.edg.model.User;

import java.util.ArrayList;

/**
 * Created by Administrator on 2016/6/15.
 */
public class UserInfoActionOrPhotoActivity extends GzBaseTooolBarActivity implements View.OnClickListener{

    private FrameLayout mChat;
    private RadioButton mChat_redio,mReply_redio;
    private TextView mLine1;
    private FrameLayout mReply;
    private TextView mLine2;
    private android.support.v4.view.ViewPager mViewpager2;
    private MyPagerAdapter myPagerAdapter;
    private ArrayList<Fragment> fragmentList=new ArrayList<>();;
    @Override
    public int getContentView() {
        return R.layout.activity_action_photo;
    }

    @Override
    public void setTitleBarView() {
    }

    @Override
    public void initView() {
        mChat = (FrameLayout) findViewById(R.id.chat);
        mLine1 = (TextView) findViewById(R.id.line1);
        mReply = (FrameLayout) findViewById(R.id.reply);
        mLine2 = (TextView) findViewById(R.id.line2);
        mChat_redio= (RadioButton) findViewById(R.id.radio_chat);
        mReply_redio= (RadioButton) findViewById(R.id.radio_reply);
        mViewpager2 = (ViewPager) findViewById(R.id.viewpager2);
        mChat.setOnClickListener(this);
        mReply.setOnClickListener(this);
        mChat_redio.setOnClickListener(this);
        mReply_redio.setOnClickListener(this);
        findViewById(R.id.main_black_1).setOnClickListener(this);
    }

    @Override
    public void initData() {
        User user= (User) getIntent().getSerializableExtra("user");
        myPagerAdapter=new MyPagerAdapter(getSupportFragmentManager());
        fragmentList.add(OtherUserBBFragment.newInstance(user,0));
        fragmentList.add(OtherUserImageFragment.newInstance(user));
        myPagerAdapter.setFragmentList(fragmentList);
        mViewpager2.setAdapter(myPagerAdapter);
        mViewpager2.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
            @Override
            public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

            }

            @Override
            public void onPageSelected(int position) {
                try {
                    switch (position) {
                        case 0:
                            mChat_redio.setChecked(true);
                            mReply_redio.setChecked(false);
                            mLine1.setVisibility(View.VISIBLE);
                            mLine2.setVisibility(View.GONE);
                            break;
                        case 1:
                            mChat_redio.setChecked(false);
                            mReply_redio.setChecked(true);
                            mLine1.setVisibility(View.GONE);
                            mLine2.setVisibility(View.VISIBLE);
                            break;
                    }
                } catch (Exception e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

            @Override
            public void onPageScrollStateChanged(int state) {

            }
        });
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.main_black_1:
                finish();
                break;
            case R.id.radio_chat:
            case R.id.chat:
                mChat_redio.setChecked(true);
                mReply_redio.setChecked(false);
                mLine1.setVisibility(View.VISIBLE);
                mLine2.setVisibility(View.GONE);
                mViewpager2.setCurrentItem(0);
                break;
            case R.id.radio_reply:
            case R.id.reply:
                mChat_redio.setChecked(false);
                mReply_redio.setChecked(true);
                mLine1.setVisibility(View.GONE);
                mLine2.setVisibility(View.VISIBLE);
                mViewpager2.setCurrentItem(1);
                break;
        }
        }
        public class MyPagerAdapter extends FragmentPagerAdapter {

            ArrayList<Fragment> fragmentList;

            public MyPagerAdapter(FragmentManager fm) {
                super(fm);
            }

            @Override
            public CharSequence getPageTitle(int position) {
                return "";
            }

            @Override
            public int getCount() {
                return fragmentList.size();
            }

            @Override
            public Fragment getItem(int position) {
                return fragmentList.get(position);
            }


            public void setFragmentList(ArrayList<Fragment> fragmentList) {
                this.fragmentList = fragmentList;
            }
        }
}
